package com.qdc.datacenters.domain;

import com.alibaba.fastjson.JSONObject;
import com.qdc.datacenters.constant.HttpStatus;
import lombok.Data;

/**
 * @author danmo
 * @date 2024-02-21 09:55
 **/
@Data
public class ResponseResult<T> {

    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息，如果有错误时，前端可以获取该字段进行提示
     */
    private String msg;
    /**
     * 查询到的结果数据，
     */
    private T data;

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult success() {
        return ResponseResult.success("操作成功",null);
    }


    public static <T> ResponseResult<T> success(T data) {
        return ResponseResult.success("操作成功", data);
    }


    public static <T> ResponseResult<T> success(String msg, T data) {
        return (ResponseResult<T>) new ResponseResult(HttpStatus.SUCCESS, msg, data);
    }

    public static  <T>  ResponseResult<T> error(String msg, T data) {
        return new ResponseResult<T>(HttpStatus.ERROR, msg, data);
    }

    public static ResponseResult error(String msg) {
        return ResponseResult.error(msg, null);
    }

    public static ResponseResult error(Integer code, String msg) {
        return new ResponseResult(code, msg, null);
    }

}
